package com.jeeplus.modules.basicdata.standard.service;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.basicdata.basictree.entity.PartDevice;
import com.jeeplus.modules.basicdata.standard.entity.*;
import com.jeeplus.modules.basicdata.standard.mapper.BasicdataCheckFormMapper;
import com.jeeplus.modules.basicdata.standard.mapper.BasicdataCheckStandardMainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class CheckRepeatedEntryService {
    @Autowired
    private BasicdataCheckStandardMainMapper basicdataCheckStandardMainMapper;
    @Autowired
    private BasicdataCheckFormMapper basicdataCheckFormMapper;
    @Autowired
    private BasicdataGiveOilMainFormService basicdataGiveOilMainFormService;
    @Autowired
    private BasicdataOilCheckStanarrdService basicdataOilCheckStanarrdService;
    @Autowired
    private BasicdataRepairService basicdataRepairService;
    public void CheckGet(String id , String partdevice){
        BasicdataCheckStandardMain basicdataCheckStandardMain = basicdataCheckStandardMainMapper.get(id);
        basicdataCheckStandardMain.setBasicdataCheckFormList(basicdataCheckFormMapper.findList(new BasicdataCheckForm(basicdataCheckStandardMain)));
        String uuid = UUID.randomUUID().toString().replace("-", "");
        basicdataCheckStandardMain.setId(uuid);
        PartDevice partDevice = basicdataCheckStandardMain.getPartDevice();
        partDevice.setId(partdevice);
        basicdataCheckStandardMain.setPartDevice(partDevice);
        basicdataCheckStandardMainMapper.insert(basicdataCheckStandardMain);
        for (BasicdataCheckForm basicdataCheckForm : basicdataCheckStandardMain.getBasicdataCheckFormList()){
            basicdataCheckForm.setCheckName(basicdataCheckStandardMain);
            basicdataCheckForm.preInsert();
            basicdataCheckFormMapper.insert(basicdataCheckForm);
        }
    }
    public void GiveOill(String id , String partdevice){
        BasicdataGiveOilMainForm basicdataGiveOilMainForm = basicdataGiveOilMainFormService.get(id);
        String uuid = UUID.randomUUID().toString().replace("-", "");
        basicdataGiveOilMainForm.setId(uuid);
        PartDevice partDevice = basicdataGiveOilMainForm.getPartDevice();
        partDevice.setId(partdevice);
        basicdataGiveOilMainForm.setPartDevice(partDevice);
        basicdataGiveOilMainForm.setIsNewRecord(true);
        basicdataGiveOilMainFormService.save(basicdataGiveOilMainForm);
    }
    public void OilCheck(String id , String partdevice){
        BasicdataOilCheckStanarrd basicdataOilCheckStanarrd = basicdataOilCheckStanarrdService.get(id);
        String uuid = UUID.randomUUID().toString().replace("-", "");
        basicdataOilCheckStanarrd.setId(uuid);
        PartDevice partDevice = basicdataOilCheckStanarrd.getPartDevice();
        partDevice.setId(partdevice);
        basicdataOilCheckStanarrd.setPartDevice(partDevice);
        basicdataOilCheckStanarrd.setIsNewRecord(true);
        basicdataOilCheckStanarrdService.save(basicdataOilCheckStanarrd);
    }
    public void Repir(String id , String partdevice){
        BasicdataRepair basicdataRepair = basicdataRepairService.get(id);
        String uuid = UUID.randomUUID().toString().replace("-", "");
        basicdataRepair.setId(uuid);
        PartDevice partDevice = basicdataRepair.getPartDevice();
        partDevice.setId(partdevice);
        basicdataRepair.setPartDevice(partDevice);
        basicdataRepair.setIsNewRecord(true);
        basicdataRepairService.save(basicdataRepair);
    }

}
